//
//  sendFirCirComment.m
//  tcpoctest
//
//  Created by gump on 5/10/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "sendFirCirComment.h"

#import "FirCirSendCommentInfo.h"

@implementation sendFirCirComment

-(void)SendFCComment:(FirCirSendCommentInfo *)fcsci
{
    //发送 74char(1),11char(1),用户名长度char(1),
    //用户名char(x),动态ID字串长度char(1),动态ID字串char(x),
    //对谁说名称长度char(1),对谁说名称char(x),
    //区分值char(1)1文字\2语音,二进制数据长度int，二进制数据char(x),
    
    if (![self CheckLogin]) {
        return;
    }
    
    switch (fcsci.istindex) {
        case FCG_ONE_TEXT:
        {
            const char *textchar = [fcsci.content UTF8String];
            int l = CHAR_PL * 6 + INT_PL * 2 + strlen(textchar) +
            [fcsci.mail length] + [fcsci.speakto length] + [fcsci.newid length];
            
            [self initDataByLength:l];
            
            [sb WriteChar:[fcsci.mail length]];
            [sb WriteString:fcsci.mail withLength:[fcsci.mail length]];
            
            [sb WriteChar:[fcsci.newid length]];
            [sb WriteString:fcsci.newid withLength:[fcsci.newid length]];
            
            [sb WriteChar:[fcsci.speakto length]];
            [sb WriteString:fcsci.speakto withLength:[fcsci.speakto length]];
            
            [sb WriteChar:fcsci.istindex];
            
            [sb WriteInt:strlen(textchar) withNTT:NTT_SMALL2BIG];
            [sb WriteString:fcsci.content withLength:strlen(textchar)];
            
        }
            break;
        case FCG_ONE_SOUND:
        {
            NSData *voicedata = [NSData dataWithContentsOfFile:fcsci.content];
            int l = CHAR_PL * 6 + INT_PL * 2 + [voicedata length] +
            [fcsci.mail length] + [fcsci.speakto length] + [fcsci.newid length];
            
            [self initDataByLength:l];
            
            [sb WriteChar:[fcsci.mail length]];
            [sb WriteString:fcsci.mail withLength:[fcsci.mail length]];
            
            [sb WriteChar:[fcsci.newid length]];
            [sb WriteString:fcsci.newid withLength:[fcsci.newid length]];
            
            [sb WriteChar:[fcsci.speakto length]];
            [sb WriteString:fcsci.speakto withLength:[fcsci.speakto length]];
            
            [sb WriteChar:fcsci.istindex];
            
            [sb WriteInt:[voicedata length] withNTT:NTT_SMALL2BIG];
            [sb WriteData:(char *)[voicedata bytes] withLength:[voicedata length]];
            
        }
            break;
        default:
            break;
    }
    
    [self Package];

}

@end
